package com.yhos.platform.oopston.core.mybatis;

import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class CommonMapper {

    public <T extends BaseEntity> void setBaseEntityAdd(T entity, Long addedUserId) {
        Date now = new Date();
        entity.setInUid(addedUserId);
        entity.setInTime(now);
        entity.setUpdateUid(addedUserId);
        entity.setUpdateTime(now);
        entity.setDeleteYn((byte) 0);
    }

    public <T extends BaseEntity> void setBaseEntityModify(T entity, Long updatedUserId) {
        entity.setUpdateUid(updatedUserId);
        entity.setUpdateTime(new Date());
    }

    public <T extends CommonBaseEntity> void setBaseEntityAdd(T entity, Long addedUserId) {
        Date now = new Date();
        entity.setInuid(addedUserId);
        entity.setIntime(now);
        entity.setUpdateuid(addedUserId);
        entity.setUpdatetime(now);
        entity.setDeleteyn((byte) 0);
    }

    public <T extends CommonBaseEntity> void setBaseEntityModify(T entity, Long updatedUserId) {
        entity.setUpdateuid(updatedUserId);
        entity.setUpdatetime(new Date());
    }

}
